package com.gzu.ltms.service.impl;

import com.gzu.ltms.entity.dto.LogisticsDTO;
import com.gzu.ltms.response.Response;
import com.gzu.ltms.service.LogisticsService;
import jakarta.annotation.Resource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public class LogisticsServiceImpl implements LogisticsService {

    @Resource
    private MongoTemplate mongoTemplate;


    /**
     * 添加物流信息到Mongodb
     * @param logisticsDTO
     * @return
     */
    @Override
    public Response<?> addLogistics(LogisticsDTO logisticsDTO) {
        mongoTemplate.insert(logisticsDTO);
        return Response.success();
    }


    /**
     * 根据id查询物流信息
     * @param id
     * @return
     */
    @Override
    public Response<List<LogisticsDTO>> getLogisticsById(Long id) {
        Query  query = new Query(Criteria.where("orderId").is(id));
        List<LogisticsDTO> list = mongoTemplate.find(query, LogisticsDTO.class);
        return Response.success(list);
    }
}
